package edu.zut.software.identity.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class Scheduler {
    @Autowired
   public CollegeController collegeController;
    @Component
    public class TestTask {
        @Scheduled(cron = "0 0/100 * * * ?")
        public void test() {
            Thread thread = new Thread(new Exetask());
            thread.start();
            System.out.println(thread.getName() + "===============begin" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));

        }

        class Exetask implements Runnable {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    try {
                        if (CollegeController.stopFlag) {
                            throw new InterruptedException();
                        }
                        collegeController.updateStu();
                        Thread.sleep(1000*60*30);
                        System.out.println(Thread.currentThread().getName() + "   " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
                    } catch (InterruptedException e) {
                        System.out.println(Thread.currentThread().getName() + "  stop!!!");
                        break;
                    }
                }
            }
        }

    }

}
